package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.systemDocumentPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * ClassName:systemDocumentMapp
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/7/27 23:07
 * @Version 1.0
 */
@Mapper
public interface systemDocumentMapp {
    //输入一个字段名称和字段变量，插入一行。这一行只保留了一个参数，其他为空。
    @DS("baodingRussia")
    @Insert("insert into system_document (docName,deleteSign,establishTime) values (#{filedVal},1,#{dateTime})")
    void insertByOneFiledName(String filedName, String filedVal, LocalDateTime dateTime);
    //查询所有不同的体系文件名称
    @DS("baodingRussia")
    @Select("SELECT * FROM (" +
            "    SELECT *, " +
            "           ROW_NUMBER() OVER(PARTITION BY docName ORDER BY orderNumber ASC) AS rn " +
            "    FROM system_document " +
            "    WHERE deleteSign = 1 " + // 确保只选择 deleteSign 为 1 的记录
            ") AS ranked_docs " +
            "WHERE ranked_docs.rn = 1")
    List<systemDocumentPojo> querySystemDocName();
    //修改一个字段，是字符串的字段,和一个修改时间，现在用在了修改作业指导书的内容里面。
    @DS("baodingRussia")
    @Update("update system_document set ${fieldName}=#{fieldVal},UpdateTime=#{dateTime} where id=#{id}")
    void editFieldOneById(Integer id, String fieldName, String fieldVal, LocalDateTime dateTime);
}
